package com.example.springiocdemo;

import com.example.springiocdemo.component.UserComPonent;
import com.example.springiocdemo.configuration.BeanConfi;
import com.example.springiocdemo.configuration.UserConfiguration;
import com.example.springiocdemo.controller.UController;
import com.example.springiocdemo.controller.UserController;
import com.example.springiocdemo.entity.UserInfo;
import com.example.springiocdemo.repository.UserRepository;
import com.example.springiocdemo.service.UserService;
import org.apache.catalina.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class SpringIocDemoApplication {

    public static void main(String[] args) {
        //获取spring上下文对象
        ApplicationContext run = SpringApplication.run(SpringIocDemoApplication.class, args);
        //从Spring上下⽂中获取对象
        UserController bean = run.getBean(UserController.class);
        //使⽤对象
        bean.sayHi();
        /*
        * 常用获取bean的方法（三种）
        * 输出三种方式，结果证明地址一样，对象一样
        * */
//        //方式一：根据类型,从Spring上下⽂中获取对象
//        UserController bean = run.getBean(UserController.class);
//        bean.sayHi();
//        System.out.println(bean);
//
//        //方式二：根据bean名,从Spring上下⽂中获取对象
//        UserController bean1 = (UserController)run.getBean("userController");
//        bean1.sayHi();
//        System.out.println(bean1);
//
//        //方式三：//根据bean类型+名称, 从Spring上下⽂中获取对象
//        UserController bean2 = run.getBean("userController", UserController.class);
//        bean2.sayHi();
//        System.out.println(bean2);
//
//        UController uController =(UController) run.getBean("UController");
//        uController.sayHi();
//        System.out.println(uController);
//        UController uController1 =run.getBean(uController.class);
//        uController1.sayHi();
//        System.out.println(uController1);


    }

}
